function M = generate_mseq( poly )
    n = size(poly, 2) - 1;
    reg = [1, zeros(1, n - 1)];
    new_reg = zeros(1,n);
    for i = 1:(2^n - 1) 
        M(i) = reg(n);
        new_reg(1) = reg(n);
        new_reg(2:n) = mod(reg(1:n-1) + poly(2:n).*reg(n), 2);
        reg = new_reg;
    end
end
